import { setDiscuss, getDiscussList, getItemApi, setDianz, getDianz,   } from '../../api/discuss'
export default {
    namespaced: true,
    state: {
        list: [],
        total: 0,
        arr: [],
        Dianz: {},
        totalTwo: 0
    },
    mutations: {
        SET_LIST(state, Obj) {
            // console.log(Obj)
            state.list = Obj.data;
            state.total = Obj.total
        },
        SET_ITEM(state, obj) {
            state.arr = obj[0]
        },
        SET_DIANZAN(state, obj) {
            state.Dianz = obj.data[0];
            state.totalTwo = obj.total
        }
    },
    actions: {
        async getDiscussList({ commit }, bdid) {
            let r = await getDiscussList({ bdid });
            commit('SET_LIST', r)
        },
        async getDiscuss({ }, commentObj) {
            await setDiscuss(commentObj)
        },
        async getItemApi({ commit }, id) {
            let r = await getItemApi(id);
            commit('SET_ITEM', r.data)
            console.log(r.data)
        },
        //新增点赞
        async setDianZan({ rootState }, id) {
            await setDianz({ uids: rootState.users.list.id, bdid: id })
        },
        //获取点赞
        async getDianz({ commit }, obj) {
            // console.log(obj);
            let r = await getDianz(obj);
            // console.log(r);
            commit('SET_DIANZAN', r)
        },
        //取消点赞
        async delteDianz({ dispatch }, obj) {
            await delteDianz(obj);
            dispatch('getDianz')
        }
    },
    getters: {
    }
}